package com.jkc.xh.adapters.viewholder;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jkc.xh.R;
import com.jkc.xh.models.BussinessModel;
import com.jkc.xh.utils.Tool;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by wangjie28 on 2015/11/13.
 */
@EViewGroup(R.layout.item_bussiness)
public class BussinessItemView extends RelativeLayout {


    @ViewById(R.id.stock_name)
    TextView stock_name;

    @ViewById(R.id.stock_code)
    TextView stock_code;

    @ViewById(R.id.business_price)
    TextView business_price;

    @ViewById(R.id.itemFoward)
    TextView itemFoward;

    @ViewById(R.id.business_amount)
    TextView business_amount;

    @ViewById(R.id.business_balance)
    TextView business_balance;

    @ViewById(R.id.business_time)
    TextView business_time;


    public BussinessItemView(Context context) {
        super(context);
    }

    public BussinessItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    public void bind(BussinessModel model) {
        stock_name.setText(model.stock_name);
        stock_code.setText(model.stock_code);
        if (model.entrust_bs == 1) {
            itemFoward.setText("买入");
            setAllTextColor(getResources().getColor(R.color.text_color_red));
        } else {
            itemFoward.setText("卖出");
            setAllTextColor(getResources().getColor(R.color.text_color_blue));
        }
        business_price.setText(model.business_price);
        business_amount.setText(model.business_amount);
        business_balance.setText(model.business_balance);
        business_time.setText(Tool.formatSecondSimpleFullDate(Long.valueOf(model.business_time)));
    }


    private void setAllTextColor(int textColorId) {
        stock_name.setTextColor(textColorId);
        stock_code.setTextColor(textColorId);
        itemFoward.setTextColor(textColorId);
        business_price.setTextColor(textColorId);
        business_amount.setTextColor(textColorId);
        business_balance.setTextColor(textColorId);
        business_time.setTextColor(textColorId);
    }
}
